VERSION 5.00
Begin VB.Form LabReportForm 
   BackColor       =   &H00FFFFFF&
   BorderStyle     =   0  'None
   ClientHeight    =   9000
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   12000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   9000
   ScaleWidth      =   12000
   ShowInTaskbar   =   0   'False
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Cancel_Button 
      BackColor       =   &H008080FF&
      Caption         =   "Cancel"
      BeginProperty Font 
         Name            =   "Arial Narrow"
         Size            =   20.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   9540
      Style           =   1  'Graphical
      TabIndex        =   4
      Top             =   1380
      Width           =   1935
   End
   Begin VB.CommandButton ForwardButton 
      Caption         =   "Forward"
      BeginProperty Font 
         Name            =   "Arial Narrow"
         Size            =   20.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   6540
      TabIndex        =   3
      Top             =   360
      Width           =   1935
   End
   Begin VB.CommandButton DateBackButton 
      Caption         =   "Backward"
      BeginProperty Font 
         Name            =   "Arial Narrow"
         Size            =   20.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   300
      TabIndex        =   2
      Top             =   360
      Width           =   1935
   End
   Begin VB.CommandButton RunButton 
      Caption         =   "Print"
      BeginProperty Font 
         Name            =   "Arial Narrow"
         Size            =   20.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   9540
      TabIndex        =   0
      Top             =   360
      Width           =   1935
   End
   Begin VB.Label Label1 
      Alignment       =   2  'Center
      BackColor       =   &H00FFFFFF&
      Caption         =   "Use the Backward and Forward buttons to adjust the date for which you want to print the report and then press the Print button."
      BeginProperty Font 
         Name            =   "Arial Narrow"
         Size            =   20.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1455
      Left            =   900
      TabIndex        =   5
      Top             =   1440
      Width           =   6915
   End
   Begin VB.Label ReportDateLabel 
      Alignment       =   2  'Center
      BackColor       =   &H00FFFFFF&
      BeginProperty Font 
         Name            =   "Arial Narrow"
         Size            =   20.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   2460
      TabIndex        =   1
      Top             =   480
      Width           =   3855
   End
End
Attribute VB_Name = "LabReportForm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Const FormLeft = 650
Const FormTop = 1600
Const FormWidth = 10200
Const FormHeight = 13700

Const VLine1 = 600
Const VLine2 = 1900
Const VLine3 = 3100
Const VLine4 = 3700
Const VLine5 = 5600
Const VLine6 = 7500
Const VLine7 = 9400

Const HLine1 = 500

Dim ReportDate As String
Dim TodaysDate As String

Private Sub Cancel_Button_Click()
   HIVMenuForm.Show
   Unload Me
End Sub

Private Sub DateBackButton_Click()
   ReportDate = DateAdd("d", -1, ReportDate)
   ReportDateLabel.Caption = "Report for: " & Day(ReportDate) & "-" & MonthName(Month(ReportDate), True) & "-" & Year(ReportDate)
   ForwardButton.Enabled = True
End Sub

Private Sub Form_Load()
   ReportDate = StringDate
   TodaysDate = StringDate
   ForwardButton.Enabled = False
   ReportDateLabel.Caption = "Report for: " & Day(ReportDate) & "-" & MonthName(Month(ReportDate), True) & "-" & Year(ReportDate)
End Sub

Private Sub ForwardButton_Click()
   If DateDiff("d", ReportDate, TodaysDate) <= 1 Then
      ForwardButton.Enabled = False
   End If
   ReportDate = DateAdd("d", 1, ReportDate)
   ReportDateLabel.Caption = "Report for: " & Day(ReportDate) & "-" & MonthName(Month(ReportDate), True) & "-" & Year(ReportDate)
End Sub

Private Sub RunButton_Click()

   Dim TempY As Long
   Dim Cntr As Integer
   Dim PageNumber As Integer
   Dim QueryDate As String
   
   RunButton.Enabled = False
   DateBackButton.Enabled = False
   ForwardButton.Enabled = False
   Cancel_Button.Enabled = False
   PrintBlankSheet
  
   DoEvents
   
   QueryDate = Day(ReportDate) & "-" & MonthName(Month(ReportDate), True) & "-" & Year(ReportDate)
   If Len(QueryDate) < 11 Then 'day must be in the range 1-9 so add leading zero
      QueryDate = "0" + QueryDate
   End If
   
   'Get the details from the database
   Printer.FontSize = 11
   Printer.FontBold = False
   CnUser.Open ConnectString
   Cmd.CommandText = "SELECT TIMELAB, CLNTCODE, SEX, TEST1NAME, TEST2NAME, TEST3NAME, TEST1RESULT, TEST2RESULT, TEST3RESULT, HIV" _
                  & " FROM   client" _
                  & " WHERE  VDATE = '" & QueryDate & "'" _
                  & " AND HIV IS NOT NULL" _
                  & " ORDER BY TIMELAB"
   Cmd.CommandType = adCmdText
   Cmd.ActiveConnection = CnUser
   RsUser.Open Cmd, , adOpenStatic
   Printer.CurrentY = FormTop + HLine1 + 200
   Cntr = 1
   PageNumber = 1
   While RsUser.EOF = False
      'Number
      TempY = Printer.CurrentY
      Printer.CurrentX = FormLeft + 200
      Printer.Print Str(Cntr)
      'Time
      Printer.CurrentX = FormLeft + VLine1 + 200
      Printer.CurrentY = TempY
      Printer.Print RsUser(0)
      'Client Code
      Printer.CurrentX = FormLeft + VLine2 + 200
      Printer.CurrentY = TempY
      Printer.Print RsUser(1)
      'Sex
      Printer.CurrentX = FormLeft + VLine3 + 200
      Printer.CurrentY = TempY
      If RsUser(2) = "1" Then
         Printer.Print "M"
      Else
         If RsUser(2) = "2" Then
            Printer.Print "F"
         Else
            Printer.Print "ERROR"
         End If
      End If
      'Test#1
      Printer.CurrentX = FormLeft + VLine4 + 200
      Printer.CurrentY = TempY
      If RsUser(6) = "0" Then
         Printer.Print RsUser(3) & " (N)"
      Else
         If RsUser(6) = "1" Then
            Printer.Print RsUser(3) & " (R)"
         Else
            If RsUser(6) = "" Then
               Printer.Print "N/A"
            Else
               Printer.Print "ERROR"
            End If
         End If
      End If
      'Test#2
      Printer.CurrentX = FormLeft + VLine5 + 200
      Printer.CurrentY = TempY
      If RsUser(7) = "0" Then
         Printer.Print RsUser(4) & " (N)"
      Else
         If RsUser(7) = "1" Then
            Printer.Print RsUser(4) & " (R)"
         Else
            If RsUser(7) = "" Then
               Printer.Print "N/A"
            Else
               Printer.Print "ERROR"
            End If
         End If
      End If
      'Test#3
      Printer.CurrentX = FormLeft + VLine6 + 200
      Printer.CurrentY = TempY
      If RsUser(8) = "0" Then
         Printer.Print RsUser(5) & " (N)"
      Else
         If RsUser(8) = "1" Then
            Printer.Print RsUser(5) & " (R)"
         Else
            If RsUser(8) = "" Then
               Printer.Print "N/A"
            Else
               Printer.Print "ERROR"
            End If
         End If
      End If
      'Print the HIV Status - added at the request of Blantyre
      Printer.CurrentX = FormLeft + VLine7 + 200
      Printer.CurrentY = TempY
      Select Case RsUser(9)
         Case "00"
            Printer.Print "NEG"
         Case "01"
            Printer.Print "POS"
         Case "97"
            Printer.Print "INC"
         Case "98"
            Printer.Print "N/A"
         Case Else
            Printer.Print "ERR"
      End Select
      RsUser.MoveNext
      'If 50 then start the next page
      If Cntr Mod 50 = 0 Then
         Printer.CurrentX = 10000
         Printer.CurrentY = 15400
         Printer.Print "Page " & PageNumber
         PageNumber = PageNumber + 1
         Printer.EndDoc
         PrintBlankSheet
         Printer.FontSize = 11
         Printer.FontBold = False
         Printer.CurrentY = FormTop + HLine1 + 200
      End If
      Cntr = Cntr + 1
   Wend
   RsUser.Close
   CnUser.Close
   
   Printer.CurrentX = 10000
   Printer.CurrentY = 15400
   Printer.Print "Page " & PageNumber
   Printer.EndDoc

   HIVMenuForm.Show
   Unload Me

End Sub

Private Sub PrintBlankSheet()

   Printer.FontName = "Arial Narrow"
   Printer.PaperSize = vbPRPSA4   'Set printer for A4 paper
   Printer.FontBold = False
   Printer.FontItalic = False
   Printer.FontUnderline = False
   Printer.Orientation = 1
   Printer.DrawWidth = 1
   
   Printer.FontSize = 12
   Printer.CurrentX = 1700
   Printer.CurrentY = 500
   
   Select Case SiteCodeConst
      Case "01"
         Printer.Print "MALAWI AIDS COUNSELLING AND RESOURCE ORGANISATION - BLANTYRE BRANCH"
      Case "02"
         Printer.Print "MALAWI AIDS COUNSELLING AND RESOURCE ORGANISATION - LILONGWE BRANCH"
      Case "03"
         Printer.Print " MALAWI AIDS COUNSELLING AND RESOURCE ORGANISATION - MZUZU BRANCH"
      Case "11"
         Printer.Print "   LIGHTHOUSE VOLUNTARY COUNSELING & TESTING - LIGHTHOUSE CENTRE"
      Case "12"
         Printer.Print " LIGHTHOUSE VOLUNTARY COUNSELING & TESTING -  "
      Case "13"
         Printer.Print " LIGHTHOUSE VOLUNTARY COUNSELING & TESTING -  "
      Case "14"
         Printer.Print " LIGHTHOUSE VOLUNTARY COUNSELING & TESTING -  "
      Case "15"
         Printer.Print " LIGHTHOUSE VOLUNTARY COUNSELING & TESTING - "
      Case "16"
         Printer.Print " LIGHTHOUSE VOLUNTARY COUNSELING & TESTING - "
        ' Version_Label.Caption = "Version: " & Version_Const & " - Mzuzu Site"
      Case Else
         Printer.Print "MALAWI AIDS COUNSELLING AND RESOURCE ORGANISATION - UNKNOWN BRANCH"
   End Select
   Printer.FontSize = 14
   Printer.CurrentX = 2350
   Printer.Print "DIAGNOSTIC RESULTS AND SPECIMEN TRACKING SHEET"
   Printer.FontSize = 14
   Printer.CurrentX = 5000
   Printer.Print Day(ReportDate) & "-" & MonthName(Month(ReportDate), True) & "-" & Year(ReportDate)

   'draw the rectangular box
   RC = PrintRect(FormLeft, FormTop, FormWidth, FormHeight)
   'Add the horizontal line
   Printer.Line (FormLeft, FormTop + HLine1)-Step(FormWidth, 0)
   'Add vertical lines
   Printer.Line (FormLeft + VLine1, FormTop)-Step(0, FormHeight)
   Printer.Line (FormLeft + VLine2, FormTop)-Step(0, FormHeight)
   Printer.Line (FormLeft + VLine3, FormTop)-Step(0, FormHeight)
   Printer.Line (FormLeft + VLine4, FormTop)-Step(0, FormHeight)
   Printer.Line (FormLeft + VLine5, FormTop)-Step(0, FormHeight)
   Printer.Line (FormLeft + VLine6, FormTop)-Step(0, FormHeight)
   Printer.Line (FormLeft + VLine7, FormTop)-Step(0, FormHeight)
   'Do the column labels
   Printer.FontSize = 10
   Printer.FontBold = True
   'No.
   Printer.CurrentX = FormLeft + 100
   Printer.CurrentY = FormTop + 150
   Printer.Print "No."
   'Time
   Printer.CurrentX = FormLeft + VLine1 + 100
   Printer.CurrentY = FormTop + 150
   Printer.Print "Time"
   'Client Code
   Printer.CurrentX = FormLeft + VLine2 + 100
   Printer.CurrentY = FormTop + 150
   Printer.Print "Client Code"
   'Sex
   Printer.CurrentX = FormLeft + VLine3 + 100
   Printer.CurrentY = FormTop + 150
   Printer.Print "Sex"
   'Test #1
   Printer.CurrentX = FormLeft + VLine4 + 100
   Printer.CurrentY = FormTop + 150
   Printer.Print "Test #1"
   'Test #2
   Printer.CurrentX = FormLeft + VLine5 + 100
   Printer.CurrentY = FormTop + 150
   Printer.Print "Test #2"
   'Test #3
   Printer.CurrentX = FormLeft + VLine6 + 100
   Printer.CurrentY = FormTop + 150
   Printer.Print "Test #3"
   'HIV Status
   Printer.CurrentX = FormLeft + VLine7 + 100
   Printer.CurrentY = FormTop + 150
   Printer.Print "HIV"

End Sub

